<template>
    <div id="ComplaintTime">
      <datetime title="开始时间" :end-date="endDate" placeholder="请选择开始时间" @on-change="startChange"  v-model="startValue" format="YYYY-MM-DD" ></datetime>
      <datetime title="结束时间" :start-date="maxStartDate" :end-date="maxEndDate" placeholder="请选择结束时间" v-model="endValue" format="YYYY-MM-DD" ></datetime>
        <x-button type="primary" style="margin: 30px auto 0" action-type="button" @click.native="listSubmit">查 询</x-button>
    </div>
</template>

<script>
  import {  Datetime,XButton } from 'vux'
    export default {
        name: "complaint-time",
      components: {
        Datetime,
        XButton
      },
      data(){
        return{
          startValue:'',
          endValue:'',
          endDate:'',
          maxStartDate:'',
          maxEndDate:''
        }
      },
      computed:{

      },
      created () {
        let vue = this
        vue.updateTitle('查询历史订单');
        vue.updateGreenRightNum(0);
      },
      mounted(){
        this.setToday();
      },
      methods: {
        listSubmit(){
            var listType=this.$route.query.listType;
            if(this.$route.query.startTime!=undefined)this.startValue=this.$route.query.startTime;
            if(this.$route.query.endTime!=undefined)this.endValue=this.$route.query.endTime;
            var start=isNaN(parseInt(new Date(this.startValue).getTime()/1000))?'':(parseInt(new Date(this.startValue).getTime()/1000)-8*3600);
            var end=isNaN(parseInt(new Date(this.endValue).getTime()/1000))?'':(parseInt(new Date(this.endValue).getTime()/1000)+16*3600);
            this.$router.push({ name: 'complaintList', query: { listType:listType,startTime:start,endTime: end}})
        },
        startChange(value){
          this.maxStartDate=value;
          var date1=value.slice(0,6);
          var date2=parseInt(value.slice(6,7))+3;
          var date3=value.slice(7);
          var n=date1+date2+date3;
          if(this.CompareDate(n,this.endDate)){
            this.maxEndDate=this.endDate;
          }else{
            this.maxEndDate=n;
          }
        },
        setToday () {
          let now = new Date()
          let cmonth = now.getMonth() + 1
          let day = now.getDate()
          if (cmonth < 10) cmonth = '0' + cmonth
          if (day < 10) day = '0' + day
          let data= now.getFullYear() + '-' + cmonth + '-' + day;
          this.endDate=data;
        },
        CompareDate(d1,d2){
          return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
        }
      }
    }
</script>

<style scoped>
  button.weui-btn, input.weui-btn{
    width: 80%;
  }
</style>
